<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="container">
    <h1>一个会打包回家的bug</h1>
    <form name="infoForm">
        <fieldset>
            <legend>客户意见表</legend>
            <div class="form-group">
            <label >兑换卡类型</label>
            <input type="text" 
            name="fiedId539"
            class="form-control" 
            placeholder="请输入兑换卡类型">
            </div>
            <div class="form-group">
            <label >推荐人</label>
            <input type="text" 
            name="fiedId540"
            class="form-control" 
            placeholder="推荐人">
            </div>
            <div class="form-group">
            <label >地址</label>
            <input type="text" 
            name="fiedId546"
            class="form-control" 
            placeholder="地址">
            </div>
            <button type="submit" class="btn btn-default">Submit</button>
        </fieldset>
    </form>
    <script>
        // ajax 数据提交一下
        let signInfo=[
            {
                fieldId:529,
                value:undefined
            },
            {
                fieldId:540,
                value:undefined
            },
            {
                fieldId:546,
                value:undefined
            },
        ];
        const oForm=document.forms["infoForm"];
        oForm.addEventListener("submit",function(events){
            events.preventDefault();
            const formData=new FormData(this);
            console.log(formData.get('fiedId539'));
            if(formData.get('fiedId539')){
                signInfo[0]['value']=formData.get('fiedId539');
            }
            if(formData.get('fiedId540')){
                signInfo[1]['value']=formData.get('fiedId540');
            }
            if(formData.get('fiedId546')){
                signInfo[2]['value']=formData.get('fiedId546');
            }
            // 发到服务器端  序列化
            let str=JSON.stringify(signInfo);
            console.log(str,'\\\\');
            fetch('/info?data='+str)
            .then(data=>data.json())
            .then(data=>{
                console.log(data);
            })
            // console.log(signInfo);
        })
    </script>
</body>
</html>